﻿using Newtonsoft.Json;
using Omabar.BLL;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Omabar.CMS.Handler
{
    /// <summary>
    /// CountryRead 的摘要说明
    /// </summary>
    public class CountryRead : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            List<COUNTRY> countries = new List<COUNTRY>();
            string belong = string.IsNullOrEmpty(context.Request["belong"]) ? "(1=1)" : context.Request["belong"];

            try
            {
                Country_BLL bll = new Country_BLL();
                countries = bll.GetModels(string.Format("SELECT COUNTRY_ID,COUNTRY_NAME,BELONG FROM COUNTRY where BELONG='{0}'", belong));
                context.Response.Write(JsonConvert.SerializeObject(countries));
            }
            catch (Exception ex)
            {
                RESP_Info info = new RESP_Info()
                {
                    Success = false,
                    Tip = "无法获取国家信息",
                    Title = "错误",
                };

                context.Response.Write(JsonConvert.SerializeObject(info));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}